import { BasicColumn, FormSchema } from "/@/components/Table"
import { rules } from "/@/utils/helper/validator"
import { render } from "/@/utils/common/renderUtils"
import * as configTmplApi from '/@/api/infra/configTmpl';
import { useI18n } from '/@/hooks/web/useI18n';
import dictEnum from '/@/enums/dictEnum';
import { ConfigKeyEnum } from "/@/enums/configKeyEnum";
const { t } = useI18n('');

export type ConfigKey = ConfigKeyEnum


export const columns: BasicColumn[] = [
  {
    title: "名称",
    width: 160,
    dataIndex: "name",
  },
  {
    title: t('类型'),
    dataIndex: 'type',
    width: 100,
  },
  {
    title: "标识",
    width: 150,
    dataIndex: "configKey",
  },
  {
    title: t('状态'),
    dataIndex: 'status',
    width: 100,
    customRender: ({ text }) => {
      const color = text == 2 ? "red" : "green"
      return render.renderTag(render.renderDict(text, dictEnum.SysConfigStatus), color)
    },
  },
  {
    title: "创建时间",
    width: 150,
    dataIndex: "createdAt",
  },
  {
    title: "创建者",
    width: 90,
    dataIndex: "createdBy",
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    label: t('名称'),
    field: 'name',
    component: 'Input',
  },
  {
    label: t('标识'),
    field: 'configKey',
    component: 'Input',
  },
  {
    label: t('类型'),
    field: 'type',
    component: 'ApiSelect',
    componentProps: {
      api: configTmplApi.listConfigType,
      showSearch: true,
      allowClear: true,
      labelField: 'label',
      valueField: 'value',
    },
  },
]


export const beforeFormSchema: FormSchema[] = [
  {
    label: "id",
    field: "id",
    component: "Input",
    show: false,
  },
  {
    field: "name",
    label: "名称",
    componentProps: {
      readonly: true
    },
    component: "Input",
    required: true
  },
  {
    field: "type",
    label: "类型",
    componentProps: {
      readonly: true
    },
    component: "Input",
    required: true
  },
  {
    field: "configKey",
    label: "标识",
    componentProps: {
      readonly: true
    },
    component: "Input",
    required: true
  },

  {
    field: "remark",
    label: "备注",
    component: "InputTextArea",
    componentProps: {
      autoSize: {
        minRows: 2,
        maxRows: 2,
      },
    },
    required: false,
  },
]

export const afterFormSchema: FormSchema[] = [

]